﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ThreeDI.UI.Abstraction;
using ThreeDI.IP;
using SlimDX.Direct3D9;
using Application = ThreeDI.UI.Abstraction.Application;
using SlimDX;

namespace ThreeDI.UI
{
    public class App : Application
    {
        private SkyBox skybox;
        private MouseMesh mouseMesh;
        private FlexableCamera flexableCamera;
        private ThreeDI.UI.Meshs.IconMesh iconMesh;
        DesktopDescriptor myDesktop;
        DetectionManager _manager;
        TrackingInfo _info;
        public App()
        {
            //_manager = DetectionManager.Instance;
            _info = new TrackingInfo();
        }

        public override void Load()
        {
            flexableCamera = new FlexableCamera(this);
            flexableCamera.Load();
            skybox= new SkyBox(this);
            skybox.Load();
            myDesktop = new DesktopDescriptor(this);
            myDesktop.load();
            //mouseMesh= new MouseMesh(this);
            //mouseMesh.Load();
        }

        public override void Render()
        {
            //_info = _manager.ProcessFrame();

            BeginScene(Color.Blue);
            flexableCamera.Render();
            skybox.Render();

         //   _info = _manager.ProcessFrame();
            UserPoint point = (UserPoint)getPoint(_info);

            myDesktop.Render();

            //flexableCamera.changePerspective(point, (float)_info.XAngle, (float)_info.YAngle);

            // mouseMesh.Render();

            //skybox.ComputeBoundingBox();
            //MessageBox.Show("  max  " + skybox._maxValue.ToString() + "  min  " + skybox._minValue.ToString());

            //myDesktop.getMeshIcon(0).ComputeBoundingBox();
            //MessageBox.Show("  max  " + myDesktop.getMeshIcon(0)._maxValue.ToString() + "  min  " + myDesktop.getMeshIcon(0)._minValue.ToString());

            //if (skybox.InverseCollision(myDesktop.getMeshIcon(0)))
            //    MessageBox.Show("collision");



            EndScene();
            Present();
        }

        private UserPoint getPoint(TrackingInfo _info)
        {
            return new UserPoint(_info.Center.X, _info.Center.Y, _info.HeadDistance);
        }
    }
}
